Method for converting a source program having a loop including a control statement into an object program

ABSTRACT

A method for converting a source program having a loop including a control statement into an object program including the steps of detecting from the statements of a first loop of a source program a control statement (an inductive control statement) having a control expression; detecting based on the control expression a turning form indicating whether a change of a turning number representing a loop iteration count indicates changes from values for a successful branch to values for an unsuccessful branch or vice versa and a turning point type indicating whether the turning number is an initial iteration count, a final iteration count, or an intermediate iteration count of the first loop; generating a string of statements having a loop not including the control statement and generating an execution result identical to an execution result of the first loop based on the first loop, the turning number, the turning form and the turning point type detected on the control statement; and converting the generated string of statements into an object code.

BACKGROUND OF THE INVENTION

The present invention relates to a method for converting a sourceprogram having a loop including a control statement and a plurality ofstatements to be repetitiously executed into an object program.

Source programs include so-called loops in many cases, each loopcontaining a plurality of statements to be repetitiously executed. Sincethe loop is subjected to an iterative execution, most of the timerequired for an execution of an object program is allocated to an objectprogram generated corresponding to the loop. Among the code optimizationtechniques heretofore developed to reduce the execution time of anobject program, most of these techniques are implemented by payingattention to the loop.

The "Supercomputer HITAC S-810 FORTRAN COMPILER, VO S3 FORT 77/HAP",Hitachi Hyoron, Vol. 65, No. 8, pp. 551-555, (1983) or "A VectorizationAlgorithm for Control Statement", Journal of Information Processing,Vol. 7, No. 3, pp. 170-174, (1984) describes a method for converting theloop structure in which two kinds of statements, i.e. the loop invariantcontrol statement (for which a result is predetermined independently ofthe iteration of the loop) and the loop starting-point control statement(for which the judgment of the initial execution of the loop is reversedwith respect to that of the subsequent execution of the loop) from thecontrol statements in a loop, thereby obtaining the same results for theloops before and after the conversion. A loop expansion method appliedto a case of a loop starting-point control statement will be describedwith reference to FIG. 2.

In FIG. 2, reference numeral 700 denotes an example of a FORTRAN programincluding the starting-point control statement, which is indicated by ○1Examining the characteristic of the condition IF (I. EQ. 1) in thecontrol statement ○1 , the variable I is used to control the loopiteration count, namely, the condition is satisfied at the startingpoint (I=1) of the loop and the condition is not satisfied at otheriterations.

If the portions ○2 , ○3 , and ○4 to be initially (I=1) executed in theiteration of the loop are moved to locations outside the loop so as toachieve the loop iteration beginning from the second execution (I=2) thecontrol statement in the loop becomes to be permanently false, whichenables to unnecessitate the control statement and hence to remove thecontrol statement ○1 , the executable statement ○5 when the condition issatisfied, the ELSE statement, and the END statement. The result of theconversion accomplished on the loop structure becomes to be as shown ina program 702 of FIG. 2.

As methods for converting the loop structure to solve the problemassociated with the control statement, there have only been known themethods described in the above-mentioned paper for effecting theconversion on the two kinds of control statements (i.e. the loopstarting-point control statement and the loop invariant controlstatement), namely, other kinds of control statements have not beendiscussed with respect to the loop structure conversion.

As described above, among the control statements in a loop, only thelimited kinds of control statements can be processed to solve theproblems associated therewith.

SUMMARY OF THE INVENTION

It is therefore an object of the present invention to expand the objectsof the resolvable control statements, and more concretely, to provide anexpansion method for resolving the following two kinds of controlstatements.

(1) A control statement to judge the last iteration of the loop

(2) A control statement to judge a particular iteration during the loopiteration

Another object of the present invention is to provide a method forsystematically effecting the resolution of the loop starting-pointcontrol statement of the conventional technique and the two controlstatements described above.

To this end, according to the present invention, there is provided amethod including a step for detecting from the statements of a firstloop of a source program a control statement (an inductive controlstatement) including a control expression specifying variablesconstituted from a linear function C₁ n+C₂ of the loop iteration countn, the variables being to be judged for a branch, where C₁ and C₂ areconstants, loop invariant variables, or functions thereof; a step fordetecting based on the control expression a turning form indicatingwhether a change of a turning number representing a loop iteration countfor which a value of the control expression of the detected inductivecontrol statement and the change of the value of the control expressionindicates changes from values for a successful branch to values for anunsuccessful branch or vice versa and a turning point type indicatingwhether the turning number is an initial iteration count, a finaliteration count, or an intermediate iteration count of the first loop; astep for generating a string of statement having a loop not includingthe control statement and generating an execution result identical to anexecution result of the first loop based on the first loop and theturning number, the turning form, and the turning point type detected onthe control statement; and a step for converting the generated string ofstatements into an object code.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention will be apparent from the following detaileddescription taken in conjunction with the accompanying drawings inwhich:

FIG. 1 is a schematic configuration diagram illustrating an inductivecontrol expanding part of an embodiment according to the presentinvention;

FIG. 2 is a schematic diagram for explaining an inductive controlexpanding part of the prior art;

FIG. 3 is a general flowchart of a compiler program to which the presentinvention is applied;

FIG. 4 is an explanatory diagram illustrating the content of theoperation of the inductive control expanding part to which the presentinvention is applied;

FIG. 5 is a schematic diagram showing the data structures necessary forthe operation of FIG. 1;

FIG. 6 is an explanatory diagram illustrating sort values in theinductive control table shown in FIG. 5;

FIG. 7 is a schematic diagram illustrating control expression types inthe inductive control table shown in FIG. 5.

FIG. 8 is a diagram for explaining the loop structure conversion for arelative operator EQ/NE;

FIG. 9 is a flowchart illustrating an inductive control detecting part;and

FIG. 10 is a flowhcart illustrating the processing of a part fordetermining the object of the inductive control expansion.

DESCRIPTION OF THE PREFERRED EMBODIMENTS

Prior to the detailed description of an embodiment, the principle of theembodiment will be described.

In this embodiment, a compiler is provided with an inductive controlexpanding part, which includes an inductive control detecting part, aninductive control characteristic analyzing part, an inductive controlexpansion object detecting part, and a loop structure converting part.

(1) The inductive control detecting part detects from the statements ina loop of a source program a control statement (inductive controlstatement) including a control expression specifying as a variable to bejudged for a branch a variable represented as a linear function C₁ n+C₂of the loop iteration count n, where C₁ and C₂ are constants, loopinvariant variables or functions thereof.

(2) The inductive control characteristic analyzing part detects based onthe control expression a turning form indicating whether a change of aturning number representing a loop iteration count for which a value ofthe control expression of the detected inductive control statement andthe change of the value of the control expression indicate changes fromvalues for a successful branch to values for an unsuccessful branch orvice versa and a turning point type indicating whether the turningnumber is an initial iteration count, a final iteration count, or anintermediate iteration count of the loop part.

(3) The part for determining the object of the inductive controlexpansion, when a plurality cf inductive control statements are detectedin the step (1), arranges the inductive control statements in orderbased on the turning point type and the turning; number of eachinductive control statement.

(4) The loop structure converting part generates a string of statementsgenerating an execution result identical to an execution result of theloop based on the loop and the turning number, the turning form, and theturning point type detected based on the condition statement(s).

Through the steps described above, a loop including an inductive controlstatement can be converted into a loop not including an inductivecontrol statement.

The components of the inductive control expanding part operate on eachpart of a loop in a source program as follows.

(1) The inductive control detecting part examines the statements and theexpressions included in the loop to detect an inductive controlexpression. That is, each statement is examined and is checked for aninductive control statement. If an inductive statement is detected, thecontrol expression thereof is examined to judge whether the expressionis an inductive control expression or not.

The inductive control expression here is represented as a linearfunction C₁ n+C₂ of the loop iteration count n, where the coefficientsC₁ and C₂ are constants, loop invariant variables (of which values arenot changed in the loop), or functions thereof.

Incidentally, the loop iteration count is not explicitly expressed as avariable in an inductive control expression in some cases. For example,in the loop of the program 700 of FIG. 2, the variable I is equal to theloop iteration count n; however, in the loop of the program 702 of FIG.2, the variable I is different from the loop iteration count n, namely,there exists a relationship of I=n+1. In general, an inductive controlexpression includes or does not include the loop iteration count n as anexplicit variable.

The definition of an inductive control expression can be alternativelydefined as follows. First, an inductive variable is defined to be avariable which is selected from the variables expressed in a loop of asource program and which has a value representable by use of a linearfunction C₃ n+C₄ of the loop iteration count n, where C₃ and C₄ areconstants or loop invariant variables. The I's in the loops of theprograms 700 and 702 of FIG. 2 are both inductive variables. Aninductive control expression f(t) is represented as a linear function C₅I+C₆ of the inductive variable I, where C₅ and C₆ are constants or loopinvariant variables. Then,

    I=C.sub.3 n+C.sub.4                                        (1)

    f(I)=C.sub.5 I+C.sub.6 =(C.sub.5 C.sub.3)n+(C.sub.4 C.sub.5 +C.sub.6) (2)

result and satisfy the definition of the inductive control expression.

An inductive control expression is detected as follows.

(a) Registration of inductive variables

Among the variables included in the loop, those expressed by theexpression (1) are detected and registered.

(b) Registration of inductive expressions

For each inductive variable, an expression (called an inductiveexpression) containing the variable as an element thereof is registered.

(c) Registration of inductive control expressions

Among the inductive expressions registered in the step (b), thoserepresented as control expressions in a control statement are registeredas inductive control expressions to an inductive control expressiontable.

(2) The inductive control characteristic analyzing part performs ananalysis on each inductive control expression registered to theinductive control expression table to judge the type of the inductivecontrol expression. Namely, the point (the starting, ending, ormiddlepoint) of the loop iteration at which the judged value of theinductive control expression is turned or inverted and the turning formof the judged value of the control expression in the neighborhood of theturning point are examined as follows.

(a) Judgment of a turning point

The inductive control expression f(I) is a linear function of the loopiteration count n.

    f(I)=g(n)≡C.sub.7 *n+C.sub.8 ·rop·C.sub.9 (3)

where, C₇, C₈, and C₉ are constants, loop invariant variables, orexpressions constituted therefrom

For the judgment, the relative operator of the expression is regarded asEQ (equal sign) to solve the equation

    C.sub.7 *n+C.sub.8 =C.sub.9                                (4)

From the expression (4),

    n=(C.sub.9 -C.sub.8)/C.sub.7                               (5)

is obtained.

The loop iteration count n ranges from 1 to the loop number l. Thecharacteristic of the control expression can be judged depending on thevalue of the solution n of the expression (5), and the type of therelative operator, and the positive/negative sign of C₇ value of theexpression (5). An operation of judgment will be described withreference to an example of a case where the relative operator is GT (thesubject is greater than the object) and the value of C₇ is positive.

(i) n=1

For the first loop iteration, the expression (3) becomes false, whereasfor the second and subsequent iterations, the expression (3) becomestrue; consequently, the control expression is a starting-point inductivecontrol expression.

(ii) n=l

Since the expression (3) is false for all loop iterations, the controlexpression is a permanently false control statement.

(iii) 1<n<l

"False" results for the loop iterations up to the n-th iteration, and"true" results for the (n+1)-th and subsequent iterations; consequentlythis control expression is a middle-point inductive control expression.

(iv) n<1

Since the expression (3) is true for all loop iterations, this controlexpression is a permanently true control statement.

(v) n>l

Since the expression (3) is false for all loop iterations, this controlexpression is a permanently false control statement.

For other relative operators and in a case where the value of C₇ isnegative, the type of the inductive control expression can be determinedby effecting the similar judgment.

(b) Examination of turning form

For the relative operators EQ (equal to) and NE (not equal to), theturning form may be different from that of the GT in some cases. Namely,the turning form is different only when the solution n of the expression(3) is 1<n<l. For example, if the relative operator is EQ, the controlexpression is false from the first loop iteration to the (n-1)-th loopiteration, true only for the n-th iteration, and false for the (n+1)-thand subsequent iterations. If the relative operator is NE, the controlexpression is changed as true→false→true in a fashion opposite to thecase of EQ. As described above, the judged result of the controlexpression turns two times for EQ and NE.

The inductive control characteristic analyzing part achieves thecharacteristic analysis and records the result in the inductive controlexpression table.

(3) The inductive control expansion object determining part determinesthe inductive control expressions selected from a plurality of inductivecontrol expressions for the expansion and the order of expansion thereofbased on the characteristic set in the step (2) above. That is, if a lotof inductive conditions are detected in the step (1), it is notadvantageous to effect the loop expansion on all the conditions toresolve the inductive control statements because of a great size of anobject program generated as a result. To overcome this difficulty, theinductive control expressions to be expanded must be selected. Inaddition, to effectively accomplish the processing of the loop structureconversion to be described later, the inductive control expressions arearranged in order. Namely, the inductive control expressions are orderedby use of the value n of the solution of the expression (3).

(a) The inductive control expression for n≦1 is ordered as the firstlevel.

(b) The inductive control expression for n≧l is ordered as the nextlevel.

(c) The inductive control expressions for 1<n<l are ordered in theascending order of the value of n.

In order to effect the operation above, a sort value field is providedin the inductive control expression table 300. The sort values -2, -1,and n are assigned to the inductive control expressions for n+1, n≧l,and 1<n<l, respectively. The inductive control expressions can beordered as described above by executing a sorting of these expressionsin the ascending sort value order.

In an expansion of an inductive control expression, the components ofthe loop may be expanded up to two times the original components. Sincethe expressions having the same sort value are expanded at the same time(to be described later), these expressions are collectively consideredas a group. Within a range in which the loop expansion is allowed, theinductive control expression as an expansion object is selected in theascending sort value order.

(4) The loop structure converting part 44 processes for each inductivecontrol expression selected in the step (3) to generate a loop structurewhich is equivalent to the original loop structure and from which thecontrol expressions are removed. This operation is simultaneouslyachieved for the expressions having the same sort value.

(a) From the permanently true control expression, the control expressionand the ELSE-part are removed.

(b) From the permanently false control expression, the controlexpression and the THEN-part are removed.

(c) For the starting-point control expression, a part to be executed atthe loop starting point is generated at a position immediately beforethe loop and the inductive control expression and the THEN-part in theloop are erased (in a case where the expression is false at other thanthe loop starting point. The ELSE-part is erased if the expression istrue). In addition, an incrementation value is added to the initialvalue of the loop control displacement.

(d) For the ending-point control expression, a part to be executed atthe loop ending point is generated at a position immediately after theloop and the inductive control expression and the THEN-part (or theELSE-part) in the loop are erased. Moreover, the incrementation value issubtracted from the final value of the loop control variable.

(e) For the middle-point control expression, two kinds of expansionforms are used. If the relative operator is other than EQ and NE, twoloop structures are generated as follows.

(i) For the part from the first loop iteration to the (n-1)-thiteration, the inductive control expression and the THEN-part (or theELSE-part) are erased.

(ii) For the part from the n-th loop iteration to the final iteration,the inductive control expression and the ELSE-part (or the THEN-part;the part other than that of the step (i)) are erased.

If the relative operator is EQ or NE, the expression is expanded intothe following three parts.

(i) For the loop from the first loop iteration to the (n-1)-thiteration, the inductive control part and the THEN-part are erased (forEQ. The ELSE-part is erased for NE).

(ii) A part to be executed in the n-th interation.

(iii) For the loop from the (n+1)-th loop iteration to the finaliteration, the inductive control expression and the THEN-part are erased(for EQ. The ELSE-part is erased for NE).

As described above, the inductive conditions in the loop are detectedand the loop structure conversion can be accomplished to resolve theinductive conditions.

Referring now to FIGS. 1-5, an embodiment of the present invention willbe described in detail.

FIG. 3 shows a configuration of a compiler program to which the presentinvention is applied.

A compiler program 1 receives a source program as an input thereto andgenerates an object program which runs on a digital computer or a vectorcomputer.

The compiler program 1 operates as follows.

A source program analyzing part 4 reads a source program written in theFORTRAN from a mass-storage device 2 and translates the source programinto an intermediate language expression (not shown).

An intermediate language optimizing part 5 accomplishes an analysis ofthe structure and data reference relationships on the intermediatelanguage expression and converts the expression into a structure havinga high execution efficiency. Details thereabout will be described later.

A storage allocating part 6 allocates areas necessary to execute theobject program, and a register allocating part 7 allocates thegeneral-purpose registers and the floating-point registers. An objectprogram outputting part 8 outputs the object program including stringsof machine instructions to a mass storage device 3.

The configuration and the operation of the intermediate languageoptimizing part 5 will be next described.

A control flow analyzing part 10 analyzes the flow of control in theintermediate language expression to detect the control structure andloops.

A data flow analyzing part 20 analyzes the reference relationships ofthe definitions of variables. Namely, by use of the results from thecontrol flow analysis, the data flow is analyzed to determine whether ornot a value (definition) set to a variable is to be passed to a citation(reference) of the variable at other location.

A loop analyzing part 30 effects an analysis by use of the results fromthe data flow analyzing part 20 on each loop detected by the controlflow analyzing part 10. For each loop, the loop analyzing part 30generates a list of the following two kinds of variables.

(1) Loop invariant variable

A variable of which the value is unchanged regardless of the loopiteration count.

(2) Inductive variable

A variable of which the value is regularly varied depending on the loopiteration count, namely, the value for each iteration is represented byC₃ * (iteration count)+C₄, where C₃ and C₄ must be constants or loopinvariant variables.

An inductive control expanding part 40 to which the present invention isapplied achieves a loop structure conversion to detect and to resolvethe inductive control expressions by use of the results from the loopanalyzing part 30. Details of this operation will be described later.

A redundancy removing part 50 is used to effect the other optimization.

Excepting the inductive control expanding part 40, the configuration andthe operation of the compiler have been commonly known, and hence thedetailed description thereof will be omitted.

Referring now to FIGS. 1 and 5, a description will be given of theoperation of the inductive control expanding part 40 to which thepresent invention is applied.

In FIG. 1, an inductive control detecting part 41 receives as inputsthereto an intermediate language loop structure 100 and a characteristictable 200 of the loop generated by the loop analyzing part 30 of FIG. 3and generates an inductive control expression table list 300. Theconfiguration of the characteristic table 200 of the loop comprises thefollowing three components as shown in FIG. 5.

(1) Loop iteration count 210

(2) Inductive variable table list 220

A list including a first inductive variable table address 220-0 to whichinductive variable tables 220-i (i=1, 2, . . . ) are connected.

The inductive variable table 220-i includes the following fields.

(a) Next inductive variable table address 221-i

An address indicating the next inductive variable table 220-i+1; φ forthe final table.

(b) First inductive expression table address of the variable

An address indicating the first address of the inductive expressiontable associated with the inductive variable. This field is set by theloop analyzing part 30. An inductive expression table 240-ij (j=1, 2, .. . ) indicated by this field comprises the following fields.

(i) Next inductive expression table address 241-ij

An address indicating the next inductive expression table 241-i(j+1).

(ii) Intermediate language address 242-ij

An address indicating an intermediate language expression in which theinductive expression is included.

(c) First inductive control expression table address

of the variable 223-i

An address indicating the first address of the inductive controlexpression table associated with the inductive variable. This field isset by the inductive control detecting part 41.

(d) Initial value 224-i

A value of the inductive variable when the loop is started.

(e) Incrementation value 225-i

A value to be added to the inductive variable for each iteration of theloop. This may be a negative value.

(3) Loop invariant variable table list

A list including the first loop invariant variable table address 230 andloop invariant variable tables (not shown).

The inductive control expression table list 300 comprises two componentsas shown in FIG. 5, which is illustrated as an example associated withthe source program 704 of FIG. 4.

(1) Inductive control expression table 310-ij (i=1, 2, . . . i, j=1, 2,. . . )

This table is generated for each inductive variable table 220-icorresponding to the inductive control expression.

The inductive control expression table 310-ij includes the followingfields.

(a) Next control expression table address 311-ij

An address indicating the next inductive control expression table310-kl. If the next table is absent, φ is specified.

(b) Sorted next control expression table address 312-ij

This address is set after the sorting is completed and indicates thenext inductive control expression table 310-mn in the sorting order. Forthe final item, φ is specified.

(c) Pointer to intermediate language 313-ij

This indicates a location for storing the intermediate languageexpression of the inductive control expression.

(d) Sort value 314-ij

This value is used as a sorting key. Details will be described later.

(e) Control expression type 315-ij

This indicates the type of the control expression. Details will bedescribed later.

(2) Sorted first control expression table address 320

This field is used to store the address of the first inductive controlexpression table sorted according to the sort value in the inductivecontrol expression table 310-ij. (The sorting will be described later.)

The inductive control detecting part 41 analyzes the intermediatelanguage loop structure 100 to detect the inductive control expressionsincluded therein and generates an inductive control expression table310-ij corresponding to each detected inductive control expression. Forexample, in a case of the program 704 of FIG. 4, the three expressions○1 , ○2 and ○3 are detected as the inductive control expressions.

FIG. 9 shows the processing flow of the inductive control detectingpart, which operates as follows.

(1) Step 601

Obtains the content (inductive variable table address) of the firstinductive variable table address 220-0 associated with the loop.

(2) Step 602

Ends the processing if the inductive variable table address is φ.

(3) Step 603

Obtains the first inductive expression table address 222-i from theinductive variable table 221-i indicated by the inductive variable tableaddress.

(4) Steps 604 and 608

If the content is φ, in order to check the next inductive variable, thenext inductive variable table address 221-i is obtained from theinductive variable table 220-i and control is passed to the step 602 ofthe processing (2) above.

(5) Step 605

An intermediate language expression is obtained from the intermediatelanguage address field 242-ij of the inductive expression table 240-ijto check whether or not the expression is an expression (a controlexpression) in a control expression.

If the expression is not a control expression, no action is taken andcontrol is passed to the processing (7).

(6) Step 606

If the control expression is detected, an inductive control expressiontable 310-ij is generated and is registered to the inductive controlexpression table list 300, and then control proceeds to the next step.

(7) Step 608

The next inductive expression table address 241-ij is obtained from theinductive expression table 200-ij and control proceeds to the processing(4).

Next, the inductive control characteristic analyzing part 42 effects ananalysis of characteristics of each detected inductive expression andsets the characteristic values to the inductive control expression table310-ij. Namely, the following two information items are set.

(1) Sort value 314-ij (FIG. 6)

This value is used to sort the inductive control expression tables310-ij and is calculated as follows.

(a) -2 for a starting-point control expression

(b) -1 for an ending-point control expression

(c) The iteration count for a middle-point control expression, theiteration count being obtained when the judged result of the inductivecontrol expression is

first turned or inverted. The values -2 and -1 are set for the startingpoint and the ending point, respectively, so that the controlexpressions associated with the starting point and the ending points aresorted to be expanded in this sorting order in the loop structureconverting part 44, which will be described later.

(2) Control expression type 315-ij (FIG. 7)

This represents the type of the pertinent inductive control expressionas follows.

(a) Permanently true inductive control expression

There may exist a control expression for which the condition is alwayssatisfied within the range of the value of the inductive variable. Forexample, a control expression IF (I. GE. 1) is always true when theinitial value is 1 for the inductive variable I and the incrementationvalue is positive.

(b) Permanently false inductive control expression

A control expression for which the condition is always unsatisfiedwithin the range of the value of the inductive variable. For example, acontrol expression IF (I. LT. 1) is always false when the initial valueis 1 for the inductive variable I and the incrementation value ispositive.

(c) Inductive control expression for THEN turning

An inductive expression for which the judged result of the inductivecontrol expression is changed from false to true. For example, a controlexpression IF (I. GE. 10) is changed from false to true at a point ofthe iteration count=10.

(d) Inductive control expression for ELSE turning

An inductive control expression for which the judged result of theinductive control expression is changed from true to false.

(e) Control expression requiring EQ/NE expansion

A control expression for which the judged result of the inductivecontrol expression changes from false to true (or from true to false)for an iteration count and the result changes again from true to false(or from false to true) at the next iteration. For example, a controlexpression IF (I. EQ. 10) develops this change.

Next, the operation of the inductive control expansion objectdetermining part 43 will be described. This part 43 receives as an inputthereto the inductive control expression table list 300 to which thecharacteristic values have been set and sorts the items in the ascendingorder of the sort value of each inductive control expression table310-ij to generate the sorted inductive control expression table list400. The top position of the sorted inductive control tables 310-ij isset to the first sorted control expression table address 320.

The processing flow thereof will be described with reference to FIG. 10.

(1) Step 621

Obtain the first inductive variable table address 220-0 of the loop.

(2) Step 622

Check to determine whether or not an inductive variable table 220-i ispresent. If absent, control proceeds to the processing (7).

(3) Step 623

If the inductive variable table 220-i is present, obtain the firstinductive control expression table address 223-i therefrom.

(4) Steps 624 and 627

Check to determine whether or not an inductive control expression table310-ij is present. If absent, in order to check for the next inductivevariable, the next inductive variable table address 221-i is obtainedand control is passed to the processing (2).

(5) Step 625

If the inductive control expression table 310-ij is present, registerthis table 310-ij to the sort chain beginning from the sorted inductivecontrol expression table address 320. The value used for the sorting isthe sort value 314-ij set by the inductive control characteristicanalyzing part 42, and the sorting is accomplished in the ascendingorder of the sort values.

(6) Step 626

After the sorting is finished, the next inductive control expressiontable address 311-ij is obtained and then the processing (4) isexecuted.

(7) Step 628

Determine an expansion object in the sorted induction control expressiontable list 400 and set the expansion object control flag in the controlexpression type 315-ij (FIG. 7).

(a) The starting-point control expression and the ending-point controlexpression are expanded in any cases.

(b) Among the middle-point control expressions, those expressions eachhaving the same value are first selected. These expressions with theduplicated sort value are counted as 1, and if the number of suchexpressions exceeds a predetermined value, the selection of theexpansion object is stopped. The predetermined value is determinedaccording to the magnitude allowed when the object program size isincreased due to an expansion of the inductive control expression.Ordinarily, the predetermined value ranging from 2 to 4 is preferablyselected.

Finally, an operation of the loop structure converting part 44 will bedescribed. This part 44 receives as an input thereto the sortedinductive control expression table list 400 and outputs an expandedintermediate language loop structure 500. The operation will bedescribed with reference to an example of the loop structure of FIG. 4.As described above, this loop includes the following three kinds ofinductive control expressions ○1 , ○2 , and ○3 .

○1 Starting-point inductive control expression

○2 Ending-point inductive control expression

○3 Middle-point inductive control expression

The induction control expression tables corresponding to these inductivecontrol expressions ○1 , ○2 , and ○2 are sorted to be arranged in thesequence thereof and hence are expanded in this order.

(1) Loop expansion of starting-point inductive control expression

The starting-point inductive control expression ○1 is true only at thestarting point and is false for the subsequent iterations. Consequently,the intermediate language expression ○5 representing the processing tobe executed at the starting point is generated at a location immediatelybefore the loop and the initial value of the control variable of theloop is incremented by one, namely, the value is changed from 1 to 2 asshown in the expression ○7 . Thereafter, the inductive controlexpression ○1 is erased from the loop body.

(2) Loop expansion of ending-point inductive control expression ○2

The ending-point inductive control expression ○1 is true up to theending point, namely, this expression ○1 is false only at the endingpoint. Consequently, the intermediate language expression ○6representing the processing to be executed at the ending point isgenerated at a location following the loop and the final value of thecontrol variable of the loop is decremented by one, namely, the value ischanged from N to N-1. Thereafter, the inductive control expression ○2and the part <S₄ > to be executed only at the ending point are erasedfrom the loop body.

After the operations (1) and (2) above are completed, the program 704 isconverted into the program 706.

(3) Loop expansion of middle-point inductive control expression ○3

The inductive control expression ○3 is true up to the iteration count of19 and is false beginning from the iteration count of 20. Therefore, theloop is divided into two loops. Namely, up to the iteration count of 19,a loop ○8 including the THEN-part <S₂ > of the control expression ○3 isformed; and for the iteration count 20 and subsequent iteration counts,a loop ○9 including the ELSE-part (empty in this example) of the controlexpression ○3 is established. In this example, since the final value N-1of the loop iteration is represented by a variable, the middle point(19) may be located at a point succeeding the final value (N-1). Toprevent such a case, the expression ○10 is inserted to guarantee theappropriate operation regardless of the final value.

As described above, the program 704 is converted into the program 708 ofFIG. 4. As a result, the inductive control statement in the loop isresolved.

If the middle-point inductive control expression is an EQ/NE expansioncontrol expression (FIG. 7), the expansion is achieved to convert theprogram 710 into the program 712 as shown in FIG. 8. Namely, if thecontrol expression ○11 of the program 710 is a control expression havingan EQ/NE expansion condition, the expansion is accomplished in the caseto form three parts including a loop ( ○12 ) representing the partpreceding the middle point (10), a part ( ○13 ) representing the contentof execution at the middle point (10), and a loop ( ○4 ) representingthe processing after the middle point (10).

An embodiment has been described. According to the embodiment, threekinds of inductive control statements, namely, the starting-pointinductive control expression, the ending-point inductive controlexpression, and the middle-point control expression are systematicallyregistered to the inductive control expression table list 300. Theexpansion object can be selected from the inductive control expressionsregistered to the list 300 beginning from the most important item andhence the resolution of the control expression can be effected accordingto the importance of the inductive control expression. As a result, aneffective object program can be generated.

Although a compiler generating an object program has been described inthis embodiment, the present invention can be easily applied to aprecompiler and an interpreter on analogy thereto.

According to the present invention, an inductive control expression isdetected in a loop and a loop expansion is achieved according to thecharacteristic of the inductive control expression, and hence theinductive control expression is resolved, which leads to an effect thatthe execution efficiency of an object program is improved.

While the present invention has been described with reference to theparticular illustrative embodiments, it is not to be restricted by thoseembodiments but only by the appended claims. It is to be appreciatedthat those skilled in the art can change or modify the embodimentswithout departing from the scope and spirit of the present invention.

We claim:
 1. A method executed by a machine for inverting a sourceprogram having a first loop including a plurality of statements whichare written in a high level language and are repetitiously executed intoan object program for a digital computer comprising the following stepsof:(a) detecting from said statements of said first loop of said sourceprogram a control statement (an inductive control statement ) having acontrol expression specifying variables constituted from a linearfunction C₁ n+C₂ of a loop iteration count n, said variables being to bejudged for a branch, where C₁ and C₂ are constants, loop invariantvariables, or functions thereof; (b) detecting based on said controlexpression a turning form indicating whether a change of a turningnumber representing a loop iteration count for which a variable of saidcontrol expression of said detect ed control statement and a change of avalue of said control expression indicates changes from values for asuccessful branch to values for an unsuccessful branch or vice verse anda turning point type indicating whether said turning number is aninitial iteration count, a final iteration count, or an intermediateiteration count of said first loop (c) generating a string of statementshaving a loop not including said control statement and generating anexecution result identical to an execution result of said first loopbased on said first loop and said turning number, said turning form, andsaid turning point type detected on said control statement; and (d)converting said generated string of statements into an object code.
 2. Amethod according t o claim 1, wherein said step (c) includes thefollowing steps of:generating a second string of statements from saidfirst loop when a first inductive control statement which turns at afirst iteration count or a last iteration count of said first loop and asecond inductive control statement which turns at an intermediateiteration count are both detected in said step (a), said second stringof statements having a second loop including said second inductivestatement and not including said first inductive control statement andbringing forth a result identical to an execution result of said firstloop; generating from said second string of statements a third string ofstatements which has two third loops not including said first and secondinductive control statements and which brings forth an execution resultidentical to said second string of statements.
 3. A method according toclaim 1 wherein said step (c) includes the following steps of:generatinga first string of statements from said first loop when a plurality ofinductive control statements each turning at an intermediate iterationcount in said first loop are detected in said step (a), said firststring of statements having a loop not including an inductive controlstatement with a minimum turning number; generating a second string ofstatements from said first string of statements, said second string ofstatements not including an inductive control statement with a secondminimum turning number; and sequentially generating loops each notincluding an inductive control statement with a turning number which isnext greater than a turning number of an inductive control statement notincluded in a loop preceding said each loop.